package leetcode.动态规划;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/8/20 20:35
 * @description：https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/
 */
public class 买卖股票的最佳时机 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.maxProfit(new int[] {7,1,5,3,6,4}));
    }

    class Solution {
        public int maxProfit(int[] prices) {
            int max = 0;
            int min = prices[0];
            for (int i = 1; i < prices.length; i++) {
                min = Math.min(min, prices[i]);
                max = Math.max(max, prices[i] - min);
            }
            return max;
        }
    }
}
